import java.util.ArrayList;

/**
 * Interface for city and field and water
 * @author samkim
 *
 */
public abstract class Location {
	protected String name;
	protected ArrayList<RandomEvent> randomEvents;
	protected Location to;
	protected Location from;
	protected boolean hasWater;
	protected int length;
	public Location(String name) {
		randomEvents = new ArrayList<RandomEvent>();
		this.name = name;
	}
	
	public String getName() {
			return name;
	}
	
	public void addRandomEvent(RandomEvent r) {
		if (thereIsAStorm() && (r instanceof Rain))
			return;
		randomEvents.add(r);
	}
	public Location getNext() {
		return to;
	}
	public void setNext(Location l) {
		to = l;
	}
	
	public Location getPrevious() {
		return from;
	}
	
	public void setPrevious(Location l) {
		from = l;
	}
	
	public abstract boolean isLastCity();
	
	public boolean pickUpRandomEvents(Party party) {
		if (randomEvents.isEmpty())
			return false;
		
		
		for (RandomEvent r:randomEvents) {
			party.addRandomEvent(r);
		}
			
		randomEvents.clear();
		
		return true;
	}
	
	public void removeRandomEvent(RandomEvent randomEvent) {
		randomEvents.remove(randomEvent);
	}

	public boolean thereIsAStorm() {
		for (RandomEvent r:randomEvents)
			if (r instanceof Storm)
				return true;
		return false;
	}
	
	public void setHasWater(boolean b){
		this.hasWater=b;
	}
	
	public String toString(){
		return this.name;
	}
	public int getLength(){
		return this.length;
	}
	public boolean isFirstLocation() {
		return name.equals("Bremen");
	}

}
